﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="nhomnganh-add.aspx.cs" Inherits="VQWEB.administrator.huongnghiep.nganh.nhomnganh_add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
   <form id="frmObjects" action="" method="post">
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/huongnghiep/nhomnganh/handler";
        var url_input = '<%=ResolveUrl("~/administrator/templates/input.tpl") %>';

        $(document).ready(function () {
            if (CheckAtionInPath("add")) {
                loadform(0, "", "", "", array(null));
            }
            else if (CheckAtionInPath("edit")) {
                $.get(url_ashx, { view_nhomnganh: "view_nhomnganh", Id: GetId() }, function (data) {
                    var obj = $.parseJSON(data);
                    loadform(obj.id, obj.ma,obj.ten,obj.gioithieu, obj.active);
                });
            }

        });

        function loadform(id,ma, ten,gioithieu, active) {
            $.jqoteload(url_input, function (tmpl) {

                $("#frmObjects").single("hidden", "nhomnganh_id", id, null, null, tmpl.input_tpl);
                $("#frmObjects").single("text", "nhomnganh_ma", ma, "Mã Nhóm ngành:", null, tmpl.input_tpl);
                $("#frmObjects").single("text", "nhomnganh_ten", ten, "Tên nhóm ngành:", null, tmpl.input_tpl);
                $("#frmObjects").single("editor", "nhomnganh_gioithieu", gioithieu, "Giới thiệu:", null, tmpl.input_tpl);
                $("#frmObjects").single("checkbox", "nhomnganh_active", true, "Kích hoạt", active, tmpl.input_tpl);
                tinymce.init({ selector: 'textarea#tinymce' });
                $("#frmObjects").validate({
                    rules: { nhomnganh_ma: { required: true},nhomnganh_ten:{required: true} },
                    messages: { nhomnganh_ma: { required: null},nhomnganh_ten:{required: true} }
                });
            });

        }

        function array(value) {
            var array_select = [{ value: 'news', text: 'Type of News', selected: false },
                            { value: 'product', text: 'Type of Product', selected: false },
                            { value: 'introduction', text: 'Type of Introduction', selected: false}];

            var array_return = new Array();
            $.each(array_select, function (i, obj) {
                if (obj.value == value)
                    obj.selected = true;
                array_return.push(obj);
            });
            return array_return;
        }

        $(document).on("click", "#btnCancel", function () {
            window.location = "/admin/huongnghiep/nhomnganh/list";
        });
        $(document).on("click", "#btnSave", function () {
            if ($("#frmObjects").valid()) {
                var value = tinymce.get('tinymce').getContent();
                $("textarea[name='nhomnganh_gioithieu']").val(value);
                var arr = $("#frmObjects").serializeObject();
                $.post(url_ashx, { add_nhomnganh: window.escape(arr) }, function (data) {
                    alert(data);
                    window.location = "/admin/huongnghiep/nhomnganh/list";
                });
            }
        });
    </script>
</asp:Content>
